<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加会员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__PUBLIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">添加会员</div>
                <div class="layui-card-body" pad15>
                    <form class="layui-form" action="javascript:;" lay-filter="component-form-group" action="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">推荐人</label>
                        <div class="layui-input-inline">
                            <input type="text" id="us_pid" autocomplete="off" placeholder="请输入推荐人" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form" lay-filter="">

                        <div class="layui-form-item">
                            <label class="layui-form-label">昵称</label>
                            <div class="layui-input-inline">
                                <input type="text" id="us_name" lay-verify="nickname" autocomplete="off" placeholder="请输入昵称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-inline">
                                <input type="number" id="us_phone" value=""  autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">不可修改。</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">钱包地址</label>
                            <div class="layui-input-inline">
                                <input type="text" id="us_closed_href" lay-verify="nickname" autocomplete="off" placeholder="请输入钱包地址" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">钱包收款码</label>
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="test1">上传图片</button>
                                <input type="hidden" name="us_closed_code" id="us_closed_code">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" src="" id="demo1" width="200" style="padding-left: 100px;">
                                    <p id="demoText"></p>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="setmyinfo" onclick="sub()">确认添加</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
                            </div>
                        </div>
                    </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="__PUBLIC__/layuiadmin/layui/layui.js"></script>
<script>
    layui.use(['form', 'layer'], function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
    });
    function sub() {
        var pid = $("#us_pid").val();
        var gid = $("#us_gid").val();
        var name = $("#us_name").val();
        var phone = $("#us_phone").val();
        var us_closed_href = $("#us_closed_href").val();
        var us_closed_code = $("#us_closed_code").val();
        if(!(/^1[3456789]\d{9}$/.test(phone))){
            layer.msg("手机号码格式不正确，请重填");
            return false;
        }
        var RegUrl = new RegExp();
        RegUrl.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");//jihua.cnblogs.com
        if(!RegUrl.test(us_closed_href)) {
            layer.msg("钱包地址格式不正确，请重填！");
            return false;
        }
        $.ajax({
            type:'post',
            url:'{:url("User/userAdd")}',
            data:{us_pid:pid,us_gid:gid,us_name:name,us_phone:phone,us_closed_href:us_closed_href,us_closed_code:us_closed_code},
            success: function(data){
                if(data.code>0){
                    layer.alert(data.msg);
                }else{
                    layer.msg(data.msg,{icon:5,time:1500});
                }
            }
        });
    }
    //封面上传
    layui.use('upload', function() {
        var $ = layui.jquery
            , upload = layui.upload;

        var url = '{:url("Goods/uploads")}';
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: url
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if(res.code < 0){
                    return layer.msg(res.msg);
                }else{
                    //上传成功
                    layer.msg(res.msg);
                    $("[name=headImg]").val(res.src);
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    });
</script>
</body>
</html>